package main;

import static com.google.common.collect.Lists.newArrayList;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Collections;
import java.util.List;

import com.google.common.collect.Multiset;
import com.google.common.collect.Multisets;
import com.google.common.collect.Multiset.Entry;

public class Worker {
  private final File file;

  public Worker(File file) {
    this.file = file;
  }

  public List<Entry<String>> readData() throws FileNotFoundException {
    final Multiset<String> res = Multisets.newTreeMultiset();
    final Cleaner cleaner = new Cleaner();
    for (String line : new StringsIter(file)) {
      res.addAll(cleaner.toWords(line));
    }

    final List<Entry<String>> arrayList = newArrayList(res.entrySet());
    Collections.sort(arrayList, new CountComporator());
    return arrayList;
  }

}